import random
import uuid

import requests
from alicebot import Plugin
from langserve import RemoteRunnable


class InvokeAPIPlugin(Plugin):
    async def handle(self) -> None:
        await self.event.reply("正在思考，请稍等...")
        user_input = str(self.event.message)
        user_id = str(self.event.user_id)
        print(user_input)
        # agent_run = RemoteRunnable("http://localhost:8000/", cookies={'user_id': user_id})
        # first_response = requests.post('http://localhost:8000/my_ai/invoke', json={"user_input": user_input}).json()['data']['content']
        response = requests.post('http://localhost:8000/my_ai/retriever_invoke', json={"user_input": user_input})
        response = response.json()['data']['content']
        print(response)
        await self.event.reply(response)

    async def rule(self) -> bool:
        if self.event.adapter.name != "cqhttp":
            return False
        if self.event.type != "message":
            return False
        return self.event.message
